package cn.kshost.zqyg.manager.controller;

import cn.kshost.zqyg.manager.service.SysMenuService;
import cn.kshost.zqyg.manager.service.SysRoleMenuService;
import cn.kshost.zqyg.model.dto.system.AssginMenuDto;
import cn.kshost.zqyg.model.entity.system.SysMenu;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/system/sysRoleMenu")
public class SysRoleMenuController{
    @Autowired
    SysRoleMenuService sysRoleMenuService;
    @Autowired
    SysMenuService sysMenuService;
    @Operation(summary = "通过id获取选择的菜单id和所有的菜单列表")
    @GetMapping("/findSysRoleMenuByRoleId/{roleId}")
    public Result<Map<String,Object>> findSysRoleMenuByRoleId(@PathVariable Integer roleId){

        List<Long> roleCheckedIds =  sysRoleMenuService.findSysRoleMenuByRoleId(roleId);
        List<SysMenu> sysMenus = sysMenuService.finNodes();
        HashMap<String, Object> map = new HashMap<>();
        map.put("roleCheckedIds", roleCheckedIds);
        map.put("sysMenus", sysMenus);
        Result result = Result.build(map, ResultCodeEnum.SUCCESS);
        return result;
    }

    @Operation(summary = "传入角色id和菜单id列表 设置角色菜单表")
    @PutMapping("/modifySysRoleMenu")
    public Result<Map<String,Object>> modifySysRoleMenu(@RequestBody AssginMenuDto assginMenuDto){

        sysRoleMenuService.modifySysRoleMenu(assginMenuDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);

    }
}
